<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改固定资产信息')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-assets-edit" th:object="${fixedAssets}">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">资产编号：</label>
            <div class="col-sm-8">
                <input name="assetNumber" th:field="*{assetNumber}" readonly class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">资产名称：</label>
            <div class="col-sm-8">
                <input name="assetName" th:field="*{assetName}" readonly class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">资产类型：</label>
            <div class="col-sm-8">
                <select name="assetType" class="form-control " th:with="type=${@dict.getType('asset_type')}"
                        required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{assetType}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">资产品牌：</label>
            <div class="col-sm-8">
                <select name="assetBrand" class="form-control " th:with="type=${@dict.getType('asset_brand')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{assetBrand}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">供应商：</label>
            <div class="col-sm-8">
                <select name="supplier" class="form-control " th:with="type=${@dict.getType('asset_supplier')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{supplier}"></option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">资产型号：</label>
            <div class="col-sm-8">
                <input name="assetModel" th:field="*{assetModel}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">资产购置日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="purchaseDate" th:value="${#dates.format(fixedAssets.purchaseDate, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">资产购置价值：</label>
            <div class="col-sm-8">
                <input name="purchaseValue" th:field="*{purchaseValue}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">质保日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="warrantyDate" th:value="${#dates.format(fixedAssets.warrantyDate, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">资产位置：</label>
            <div class="col-sm-8">
                <input name="location" th:field="*{location}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">IP地址：</label>
            <div class="col-sm-8">
                <input name="ipAddress" th:field="*{ipAddress}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">SN号：</label>
            <div class="col-sm-8">
                <input name="snNumber" th:field="*{snNumber}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">MAC地址：</label>
            <div class="col-sm-8">
                <input name="macAddress" th:field="*{macAddress}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">OA编号：</label>
            <div class="col-sm-8">
                <input name="oaNumber" th:field="*{oaNumber}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">工号：</label>
            <div class="col-sm-8">
                <input name="userId" th:field="*{userId}" class="form-control" type="text" readonly="true"
                       onblur="findName()">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">使用人：</label>
            <div class="col-sm-8">
                <input name="userName" th:field="*{userName}" class="form-control" type="text" readonly="true">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">使用部门：</label>
            <div class="col-sm-8">
                <input name="department" th:field="*{department}" class="form-control" readonly type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">资产归属：</label>
            <div class="col-sm-8">
                <input name="assetOwner" th:field="*{assetOwner}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">资产状态：</label>
            <div class="col-sm-8">
                <select name="assetStatus" class="form-control " onfocus="this.defaultIndex=this.selectedIndex;"
                        onchange="this.selectedIndex=this.defaultIndex;" th:with="type=${@dict.getType('asset_status')}"
                        required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{assetStatus}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">分类：</label>
            <div class="col-sm-8">
                <select name="assetCategory" class="form-control " th:with="type=${@dict.getType('asset_category')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{assetCategory}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">属性：</label>
            <div class="col-sm-8">
                <select name="assetAttribute" class="form-control "
                        th:with="type=${@dict.getType('asset_attribut')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{assetAttribute}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var prefix = ctx + "asset/assets";
    $("#form-assets-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-assets-edit').serialize());
        }
    }

    $("input[name='purchaseDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='warrantyDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    function findName() {
        // 获取工号输入框的值
        var userId = $("input[name='userId']").val();
        // 发送GET请求到后端获取参数
        $.get("/asset/employee/getEmployeeName", {userId: userId}, function (response) {
            if (response.code == 0) {
                // 将后端返回的参数设置给使用人输入框
                $("input[name='userName']").val(response.data.employeeName);
                $("input[name='department']").val(response.data.department);
            } else {
                $("input[name='userName']").val(response.msg);
            }

        });
    }
</script>
</body>
</html>